from openpyxl.cell.text import Text


def analysis_excel_rich(cell):
    try:
        # 获取第一个单元格中的所有不同颜色的字体
        if isinstance(cell, Text):
            context = ''
            for content in cell.formatted:
                if content.rPr is None:
                    context = context + content.text
                else:
                    context = context + f'<font color="#{content.rPr.color.rgb}">{content.text}</font>'
            new_string = context.replace("\n", "<br>")
            return new_string
        else:
            return cell
    except Exception as e:
        raise Exception(e)
